<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Crypt;
class LoginRegController extends Controller
{
    //
    public function reglogin()
    {

// dd(111);
    	return view('home.enterprises.reglogin');
    }
     public function doregisterproc(Request $req)
    {

		$data = $req -> except('_token','province',"tel1_temp","tel2_temp","tel3_temp","tel","tel4_temp");
    	
    	
    	$rD = DB::table('regioncate')
    		-> where('name',$data['city'])
    		-> first();
    	$data1['compname'] = $data['compname'];
    	$data1['contactor'] = $data['contactor'];
    	$data1['sex'] = $data['sex'];
    	
    	if(!empty($data['tel1']) && !empty($data['tel2']))
    	{
    		$data1['tel'] = $data['tel1'].'-'.$data['tel2'].'-'.$data['tel3'];
    	}
    	if(!empty($data['phone']))
    	{
    		$data1['phone'] = $data['phone'];
    	}

    	$data1['username'] = $data['username'];
    	$data1['email'] = $data['email'];
    	$data1['passwd'] = Crypt::encrypt($data['passwd']);
    	$data1['province'] = $rD -> id;
    	$data1['city'] = $rD -> id;
    	
    	if($rD -> pid != 0)
    	{
    		$data1['province'] = DB::table('regioncate')
						    		-> where('id',$rD -> pid)
						    		-> first() -> id;
    	}
    	$data1['token'] = str_random(20);
    	// dd($data1);
    	$res = DB::table('enterprises') -> insert($data1);
    	// dd($data1);
    	if($res)
    	{
    		return view('home.enterprises.reglogin') -> with(['info' => '注册成功,请登录']);
    	}
    	return back() -> with(['info' => '未知错误']);
    }
}
